<?php

 include_once 'api_sdk/aliyun-php-sdk-core/Config.php';
 include_once 'api_sdk/Dysmsapi/Request/V20170525/SendSmsRequest.php';
 include_once 'api_sdk/Dysmsapi/Request/V20170525/QuerySendDetailsRequest.php';

class Alimsg 
{
    private $accessKeyId     = 'LTAID2BoRWjsgPF8';
    private $accessKeySecret = "5NNWbTBe2d4rLcQECTRPFWSsVgTZE7";
    private $tpl             = [
                     'reg'        => 'SMS_76625969',
                     'update'     => 'SMS_76625968',
                     'bind'       => 'SMS_76625969',
                     'find'       => 'SMS_76625968',
                     'login'      => 'SMS_76625971',
                     'update_pay' => 'SMS_76625973',
    ];

    public function sendSms( $tel, $tpl, $code) 
    {
        //此处需要替换成自己的AK信息
        $accessKeyId     = $this->accessKeyId;
        $accessKeySecret = $this->accessKeySecret;
        //短信API产品名
        $product = "Dysmsapi";
        //短信API产品域名
        $domain = "dysmsapi.aliyuncs.com";
        //暂时不支持多Region
        $region = "cn-hangzhou";
        
        //初始化访问的acsCleint
        $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
        DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", $product, $domain);
        $acsClient= new DefaultAcsClient($profile);
        
        $request = new Dysmsapi\Request\V20170525\SendSmsRequest;
        //必填-短信接收号码
        $request->setPhoneNumbers($tel);
        //必填-短信签名
        $request->setSignName("格信商城");
        //必填-短信模板Code
        $request->setTemplateCode($this->tpl[$tpl]);
        //选填-假如模板中存在变量需要替换则为必填(JSON格式)
        $request->setTemplateParam(json_encode(['code'=>$code]));
        //选填-发送短信流水号
        // $request->setOutId("1234");
        
        //发起访问请求
        $acsResponse = $acsClient->getAcsResponse($request);
        
        return $acsResponse;
    }

    
}




?>